﻿using MindASPCoreWebAPI.IRepository.SystemManager;
using MindASPCoreWebAPI.PoModel.SystemManager;
using MindASPCoreWebAPI.Repository.CommonLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MindASPCoreWebAPI.Repository.SystemManager
{

    //行业管理
    public class IndustrialManagementRepository : BaseRepository, IIndustrialManagementRepository
    {


        // 上下文       
        public IndustrialManagementRepository(SystemCenterMindContext systemcentermindContext) : base(systemcentermindContext)
        {
        }


        //分页显示
        public List<IndustryAdminModel> Show_IndustryAdminModel(out int totalcount,int pageindex, int pagesize, int? comstatus, string comname = "")
        {
            var sql = _systemCenterDbSoaContext.IndustryAdminModel.AsQueryable();
            if (!string.IsNullOrWhiteSpace(comname))
            {
                sql = sql.Where(a => a.com_ind_name.Contains(comname));
            }
            if (comstatus != null)
            {
                sql = sql.Where(a => a.com_ind_status == comstatus);
            }

             totalcount = sql.Count();

            return sql.OrderBy(a => a.com_ind_id).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();

        }



        //添加
        public int Add_IndustryAdminModel(IndustryAdminModel industryadminModel)
        {
            _systemCenterDbSoaContext.IndustryAdminModel.Add(industryadminModel);
            return _systemCenterDbSoaContext.SaveChanges();
        }


        //删除
        public int Delete_IndustryAdminModel(int com_id)
        {
            var sql = _systemCenterDbSoaContext.IndustryAdminModel.FirstOrDefault(a => a.com_ind_id == com_id);
            _systemCenterDbSoaContext.IndustryAdminModel.Remove(sql);
            return _systemCenterDbSoaContext.SaveChanges();
        }

        //编辑
        public IndustryAdminModel Edit_IndustryAdminModel(int com_id)
        {
            return _systemCenterDbSoaContext.IndustryAdminModel.FirstOrDefault(a => a.com_ind_id == com_id);
        }

        //修改
        public int Update_IndustryAdminModel(IndustryAdminModel industryAdminModel)
        {
            _systemCenterDbSoaContext.Entry(industryAdminModel).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            return _systemCenterDbSoaContext.SaveChanges();
        }



    }
}